using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using CodePlex.Resourceful.Amazon.S3;
using CodePlex.Resourceful;

namespace CodePlex.SpaceBlock.UI.Controls.Explore
{
    public partial class RenameControl : BaseControl
    {
        public RenameControl()
        {
            InitializeComponent();

         
        }

    

        public string NewName
        {
            get
            {
                InputboxForm parent = this.FindForm() as InputboxForm;
                return parent.ValueBox.Text.Trim(); 
            }

        }


        public bool ValidateName(string originalName, string newName)
        {
            return newName != null && newName.Length > 0 && newName != originalName && !newName.Contains(Path.Separator);
        }

        public void Initialize(string name)
        {

            string originalName = name;

            this.ParentChanged += delegate
            {
                InputboxForm parent = this.FindForm() as InputboxForm;

                parent.ValueBox.Text = originalName;

                EventHandler refresh = delegate
               {
                   parent.OKButton.Enabled = this.ValidateName(originalName, this.NewName);
                
               };

                parent.ValueBox.TextChanged += refresh;

                refresh(null, null);

            };

         

        }

    }
}
